﻿Public Class masdrginten
    Private INTEN = Nothing
    Private INTENSITY = Nothing
    Private STATUS = Nothing
    Private selectMasdrginten = "SELECT `inten` as 'รหัสความเข้มข้นของยา',`intensity` as 'ความเข้มข้นยา',`status` as 'สถานะการเปิดใช้งาน' FROM masdrginten"
    'Private selectMasdrgacc = "SELECT DGTYID, DRGTYPE, convert(bit, [STATUS]) FROM MASDRGTYPE"

    Dim connect As CONDB = CONDB.NewConnection()
    'Dim connectlocal As conlocal = conlocal.NewConnection

    Property INTEN_ As Integer
        Get
            Return INTEN
        End Get
        Set(value As Integer)
            INTEN = value
        End Set
    End Property

    Property INTENSITY_ As String
        Get
            Return INTENSITY
        End Get
        Set(value As String)
            INTENSITY = value
        End Set
    End Property

    Property STATUS_ As Boolean
        Get
            Return STATUS
        End Get
        Set(value As Boolean)
            If value = True Then
                STATUS = 1
            Else
                STATUS = 0
            End If
        End Set
    End Property

    Property selectMasdrginten_ As String
        Get
            Return selectMasdrginten
        End Get
        Set(value As String)

        End Set
    End Property

    Public Sub insertMasdrgintenData()
        If TypeOf INTENSITY Is String Then
            If connect.GetTable("SELECT inten FROM masdrginten WHERE intensity = '" & INTENSITY & "'").Rows.Count > 0 Then
                MsgBox("มีข้อมูลประเภทยานี้อยู่ในระบบแล้ว")
            Else
                Try
                    connect = CONDB.NewConnection()
                    'connectlocal = conlocal.NewConnection()
                    'Dim dischargeID As Integer

                    connect.ExecuteNonQuery("INSERT INTO masdrginten (intensity, status) VALUES ('" & INTENSITY & "', '" & STATUS & "')")
                    'dischargeID = connect.ExecuteScalar("INSERT INTO masdischarge (DISCHARGE, STATUS) VALUES ('" & masdischargeDescription & "', '" & masdischargeStatus & "'); SELECT LAST_INSERT_ID();")
                    'connectlocal.ExecuteNonQuery("INSERT INTO MASDISCHARGE (DISCHGID, DISCHARGE, STATUS) VALUES ('" & dischargeID & "', '" & masdischargeDescription & "', '" & masdischargeStatus & "')")
                    MsgBox("ท่านได้ทำการเพิ่มข้อมูลความเข้มข้นยาเรียบร้อยแล้ว")
                Catch ex As Exception
                    MsgBox(vbCrLf & ex.Message)
                End Try
                connect.Dispose()
                'connectlocal.Dispose()
            End If
        Else
            MsgBox("โปรดกรุณาระบุข้อมูลให้ถูกต้อง ต้องเป็นตัวอักษร")
        End If
    End Sub

    Public Sub editMasdrgintenData()
        If TypeOf INTENSITY Is String Then
            Try
                connect = CONDB.NewConnection()
                'connectlocal = conlocal.NewConnection()

                connect.ExecuteNonQuery("UPDATE masdrginten SET intensity = '" & INTENSITY & "', status = '" & STATUS & "' WHERE inten = '" & INTEN & "'")
                'connectlocal.ExecuteNonQuery("UPDATE MASDISCHARGE SET DISCHARGE = '" & masdischargeDescription & "', STATUS = '" & masdischargeStatus & "' WHERE DISCHGID = '" & masdischargeID & "'")
                MsgBox("ท่านได้ทำการแก้ไขข้อมูลความเข้มข้นยาเรียบร้อยแล้ว")
            Catch ex As Exception
                MsgBox(vbCrLf & ex.Message)
            End Try
            connect.Dispose()
            'connectlocal.Dispose()
        Else
            MsgBox("โปรดกรุณาระบุข้อมูลให้ถูกต้อง ต้องเป็นตัวอักษร")
        End If
    End Sub
End Class
